package com.qf.util;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ChannelMap {

    private static Map<Integer, Channel> channelMap = new ConcurrentHashMap<>();

    public static void put(Integer uid, Channel channel){
        channelMap.put(uid, channel);
    }

    public static void remove(Integer uid){
        channelMap.remove(uid);
    }

    public static Channel getChannel(Integer uid){
        return channelMap.get(uid);
    }

    public static void remove(Channel channel){
        for (Map.Entry<Integer, Channel> entry : channelMap.entrySet()) {
            if (entry.getValue() == channel) {
                remove(entry.getKey());
                break;
            }
        }
    }
}
